package com.allwees.bs.c.module.order.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.allwees.bs.core.model.order.entity.OrderModel;
import com.allwees.bs.core.model.order.wf.order.EOrderAction;
import com.allwees.bs.core.model.order.wf.order.EOrderItemState;
import com.allwees.bs.core.model.order.wf.order.EOrderState;
import com.allwees.core.wf.Workflow;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.math.BigDecimal;
import java.util.List;

@Data
@EqualsAndHashCode(callSuper = true)
@Entity
@Table(name = "o_order")
public class OrderEntity extends OrderModel implements Workflow<EOrderState, EOrderAction> {

	@Column(columnDefinition = "varchar(255)")
	@Enumerated(EnumType.STRING)
	private EOrderAction latestAction;

	@Column(columnDefinition = "varchar(255)")
	@Enumerated(EnumType.STRING)
	private EOrderState backState;

	@Column(columnDefinition = "varchar(255)")
	@Enumerated(EnumType.STRING)
	private EOrderState state;

	@Transient
	@TableField(exist=false)
	private List<OrderItemEntity> orderItems;

	@Transient
	@TableField(exist=false)
	private Integer isInfluencer;

	@Override
	public String getBsKey() {
		return uuid;
	}

	public boolean reviewAble() {
		return EOrderState.RECEIVED.equals(this.getState());
	}

	public boolean refundStatusAble() {
		return EOrderState.WAIT_SHIP.equals(getState()) || EOrderItemState.RECEIVED.equals(getState());
	}

    public boolean unPayed() {
		return EOrderState.CREATED.equals(getState());
    }

	public boolean isAmtPayedOfCoupon() {
		return BigDecimal.ZERO.compareTo(amt) == 0;
	}
}
